<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Ajax-实现异步请求-向服务器发送数据</title>
  <script src="js/jquery-3.7.1.js"></script>
</head>
<body>
<h1>Ajax-实现异步请求-向服务器发送数据</h1>
<button id="btn1">方式一</button>
<button id="btn2">方式二</button>
<p>响应结果：<span id="jg"></span></p>

<script>
  $("#btn1").click(function(){
    $.ajax({
      url:"send.do",
      type:"post",
      //方式一(字符串)：参数名1=值&参数名2=值&...
      data:"name=zs&age=18",
      success:function(data){
        $("#jg").text(data);
      },
    });
  });

  $("#btn2").click(function(){
    $.ajax({
      url:"send.do",
      type:"post",
      //方式一(对象)：{参数名1:值,参数名2:值,...}
      data: {
        name:"zs",
        age:18
      },
      success:function(data){
        $("#jg").text(data);
      },
    });
  });
</script>
</body>
</html>